*****************
* Load the data *
*****************
use "\\adsroot.itcs.umich.edu\home\hursre\Documents\Papers\Evangelical Signalling\Paper Drafts\JOP\Replication_Material\Data.dta", clear

***************
***************
*** FIGURES ***
***************
***************
****************************************************************************************************************************
* Figure 1: Across all candidates, Evangelical ballot name use rates by elecoral rule and municipal religions demographics *
**************************************************************************************************************************** 
quietly reg title i.bins##prop 
quietly margins i.bins, over (i.prop)
marginsplot, graphregion(color(white)) xsize(7) plot2opts(lpattern("--")) ///
			 legend(order(1 "Mayoral Race" 2 "City Council Race") ) ///
			 ytitle("Probability of Using Evangelical Ballot Name") ///
			 xlabel( 0 "<10%" 1 "10%-15%" 2 "15%-20%" 3 "20%-25%" 4 "25%-30%" 5 ">30%" ) ///
			 xtitle("Evangelical Share of Population") ///
			 title("")  
*******************************************************************************************************************************
* Figure 2: Across clergy candidates, Evangelical ballot name use rates by elecoral rule and municipal religions demographics *
******************************************************************************************************************************* 
quietly reg title i.bins##prop if reljob==1
quietly margins i.bins, over (i.prop)
marginsplot, graphregion(color(white)) xsize(7) plot2opts(lpattern("--")) ///
			 legend( order(1 "Mayoral Race" 2 "City Council Race") ) ///
			 ytitle("Probability of Using Evangelical Ballot Name") ///
			 xlabel( 0 "<10%" 1 "10%-15%" 2 "15%-20%" 3 "20%-25%" 4 "25%-30%" 5 ">30%" ) ///
			 xtitle("Evangelical Share of Population") ///
			 title("")
*********************************************
* Figure 3: Visual summary of main results *
********************************************
* For Evangelical title
qui reghdfe title  prop anyevan interaction i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
qui margins, at(interaction=(.00(.025).45)) 
marginsplot, title("") xtitle("Fraction of Municipal Population that is Evangelical") yscale(r(0 .01)) ylabel(0 (.002) .01)  /// 
ytitle("Difference in Predicted Probability of Using Evangelical Ballot Name", size(small)) ///
xlabel(0(.1).40) graphregion(color(white)) xsize(7) plotopts(color(black)) ciopts(color(black))
************************************************************************************
* Figure 4: Relationship between evangelical ballot name use and electoral victory *
************************************************************************************
quietly reghdfe win title##prop c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
quietly margins prop, at(title=(0(1)1))
marginsplot, graphregion(color(white)) xsize(7) plot2opts(lpattern("--")) ///
			 ytitle("Predicted Probability of Victory") ///
			 xlabel( 0 "No" 1 "Yes") ///
			 xtitle("Evangelical Ballot Name?") ///
			 title("")
*******************************************************************
** Figure A1: Winning threshold faced by City Council Candidates *
******************************************************************
histogram thresh, freq xtitle("Electoral Quota") name(rel, replace) ytitle("Number of Candidates") ///
				   ylabel(200000 "200K" 400000 "400k" 600000 "600k" 800000 "800k") ///
				 				   graphregion(color(white)) xsize(7) color(black)					   
********************************************************
** Figure A2: Vote share captured by victorious mayors *
********************************************************
* Note this requires loading in a different dataset, so I use preserve and then restore
preserve
import delimited "\\adsroot.itcs.umich.edu\home\hursre\Documents\Papers\Evangelical Signalling\Data\RawData\mayoral_share.csv", clear 
* Turning variables to numeric
gen share_turnout_n = real(share_turnout)
drop share_turnout
rename share_turnout_n share_turnout
* Creating

histogram share_turnout, freq xtitle("Vote Share Captured by Victorious Mayor") ytitle("Number of Victorious Mayors") ///
				   graphregion(color(white)) xsize(7) color(black)
restore						   							   					   
************************************************************
** Figure A3: Religious demographics across municipalities *
************************************************************
histogram anyevan, freq xtitle("Evangelical Share of Municipal Population") name(rel, replace) ytitle("Number of Candidates") ///
				   ylabel(0 "0" 25000 "25k" 50000 "50k" 75000 "75k" 100000 "100k" 125000 "150k") ///
				   graphregion(color(white)) xsize(7) color(black)
*********************************************************************************
* Figure A4: Visual summary of results using doctor ballot name placebo outcome *
*********************************************************************************
* Doctor Ballot name
qui reghdfe doctor prop anyevan interaction i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
qui margins, at(interaction=(.00(.025).45)) 
marginsplot, title("") xtitle("Fraction of Municipal Population that is Evangelical") yscale(r(0 .01)) ylabel(0 (.002) .01)  /// 
ytitle("Difference in Predicted Probability of Using a Doctor Ballot Name", size(small)) ///
xlabel(0(.1).40) graphregion(color(white)) xsize(7) plotopts(color(black)) ciopts(color(black))
***********************************************************************************
* Figure A5: Visual summary of results using Catholic ballot name placebo outcome *
***********************************************************************************
quietly reghdfe cath prop anyevan interaction i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
quietly margins, at(interaction=(.00(.025).45)) 
marginsplot, title("") xtitle("Fraction of Municipal Population that is Evangelical") yscale(r(0 .01)) ylabel(0 (.002) .01)  /// 
ytitle("Difference in Predicted Probability of Using Catholic Ballot Name", size(small)) ///
xlabel(0(.1).40) graphregion(color(white)) xsize(7) plotopts(color(black))  ciopts(color(black))


**************
**************
*** TABLES ***
**************
**************
***************************************************************
* Table 1: Shows examples of different legal and ballot names *
***************************************************************
* Each of the 6 lines below will show the candidate's information included in Table 1. Note that
* the "Occupation" row is translated from Portuguese.
* Row 1
browse ballot name prop jobname if name=="TEREZINHA MARTINS DE SOUZA" & year==2000
* Row 2
browse ballot name prop jobname if name=="GUMERCINDO  OLIVEIRA DA SILVA" & year==2004
* Row 3
browse ballot name prop jobname if ballot=="DOUTORA  LICIA" & year==2000
* Row 4
browse ballot name prop jobname if name=="RUBENS ESTEVES ROQUE" & year==2016
* Row 5
browse ballot name prop jobname if name=="VALDIR MEIRELES DE OLIVEIRA" & year==2004
* Row 6
browse ballot name year prop jobname if ballot=="CILENE AQUINO" & year==2016
*************************************************************************
* Table 2: Shows use of evangelical ballot names across all candidates *
*************************************************************************
eststo clear
* Model 1
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 2
eststo: qui reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 3
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 4 
eststo: qui reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 5
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Model 6 
eststo: qui reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Prints full table
esttab, keep (*prop anyevan *prop#c.anyevan) b(%5.4f) constant nobaselevels  se replace 
****************************************************
* Table 3: Sensitivity analysis using Oster bounds *
****************************************************
* Note that I run the baseline mode using xtreg rather than reghdfe because the psacalc package (used to calculate Oster's delta) does not recognize the reghdfe 
* ouput as a linear model. The esimates using xtreg and reghdfe, however, are identiical, which can be easily verified by comparing the output below to the ouput from Model 1
* in Table 2 estiamted above.
*
* Also note that, in the paper, I round the estimates of \delta reported below to four decimal places to maintain consistency with the rest of the paper.
xtset lcode
xtreg title prop i.eduname i.female numcandidates i.year reljob timerun population anyevan pdt psdb pt ptb pmdb, fe cluster(lcode)
* Estimate for R_{Max}=R_{Model}
psacalc delta prop, rmax(.1225)
* Estimate for R_{Max}=1.3 X R_{Model}
psacalc delta prop, rmax(0.15925)
* Estimate for R_{Max}=1
psacalc delta prop, rmax(1)
*******************************
* Table A1: Summary statistics*
*******************************
qui eststo all: estpost tabstat title prop doctor mayor vicemayor female reljob edu1 edu2 edu3 edu4 pdt psdb pt ptb pmdb other population anyevan, statistics(mean sd min max) columns(statistics) 
esttab all, cells("mean(fmt(%5.3f)) sd(fmt(%5.3f)) min(fmt(%5.2f)) max(fmt(%5.2f))")   label replace
***************************
* Table A2: See manuscript*
***************************
****************************************************************************
* Table A3: Shows use of evangelical ballot names across clergy candidates *
****************************************************************************
eststo clear
* Model 7
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if reljob==1, absorb(lcode) vce(cluster lcode)
* Model 8
eststo: qui reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if reljob==1, absorb(lcode) vce(cluster lcode)
* Model 9
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if reljob==1, absorb(lcode_year) vce(cluster lcode)
* Model 10
eststo: qui reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if reljob==1, absorb(lcode_year) vce(cluster lcode)
* Model 11
eststo: qui reghdfe title i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if everreljob==1, absorb(candidateid) vce(cluster lcode)
* Model 12
eststo: reghdfe title i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb if everreljob==1, absorb(candidateid) vce(cluster lcode)
* Prints full table
esttab, keep (*prop anyevan *prop#c.anyevan) b(%5.4f) constant nobaselevels  se replace 
***********************************************************
* Table A4: Shows use of doctor names among all candidates*
***********************************************************
eststo clear
* Model 13
eststo: qui reghdfe doctor i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 14
eststo: qui reghdfe doctor i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 15
eststo: qui reghdfe doctor i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 16 
eststo: qui reghdfe doctor i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 17
eststo: qui reghdfe doctor i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Model 18 
eststo: qui reghdfe doctor i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Prints full table
esttab, keep (*prop anyevan *prop#c.anyevan) b(%5.4f) constant nobaselevels  se replace 
*************************************************************
** Table A5: Shows use of Catholic names among all candidate*
*************************************************************
eststo clear
* Model 19
eststo: qui reghdfe cath i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 20
eststo: qui reghdfe cath i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Model 21
eststo: qui reghdfe cath i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 22
eststo: qui reghdfe cath i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(lcode_year) vce(cluster lcode)
* Model 23
eststo: qui reghdfe cath i.prop anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Model 24
eststo: qui reghdfe cath i.prop##c.anyevan i.eduname i.female numcandidates i.year reljob timerun population pdt psdb pt ptb pmdb, absorb(candidateid) vce(cluster lcode)
* Prints full table
esttab, keep (*prop anyevan *prop#c.anyevan) b(%5.4f) constant nobaselevels  se replace 
*********************************
** Table A6: Looking at victory *
*********************************
eststo clear
* Model 25
eststo: qui reg win i.title, cluster(lcode)
* Model 26
eststo: qui  reg win title##prop, cluster(lcode)
* Model 27
eststo: reghdfe win title##prop c.anyevan i.eduname i.female numcandidates i.year reljob timerun population anyevan pdt psdb pt ptb pmdb, absorb(lcode) vce(cluster lcode)
* Prints full table
esttab, keep (*title *prop) b(%5.4f) constant nobaselevels  se replace 






